<template>
  <!-- 通知通告统计页面 -->
  <div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="90"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchapi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      height="auto"
      columnsRef="notification_statistics_index_01"
    ></FilterTable>

    <!-- 详情窗口 -->
    <Drawer
      :visible.sync="visibleDrawer"
      title="通知通告查看"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>

    <!-- 已经读取数量 -->
    <Drawer
      :visible.sync="visibleReadDrawer"
      title="已读列表"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <read-feedback v-model="initReadData" @close="infoReadClose" />
    </Drawer>

    <!-- 未读取数量 -->
    <Drawer
      :visible.sync="visibleNoReadDrawer"
      title="未读列表"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <no-read-feedback v-model="initNoReadData" @close="infoNoReadClose" />
    </Drawer>
  </div>
</template>

<script>
import { pageNotificationMaintaion } from '@/api/cms-api/notification/maintain/index';
import { dictionary } from '@/utils/dictMixin';
import infoModal from './info';
import noReadFeedback from './noReadFeedback';
import readFeedback from './readFeedback';

export default {
  name:'notificationStatistics',
  mixins: [dictionary],
  components: {
    infoModal,noReadFeedback,readFeedback
  },
  data() {
    return {
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchParams: {
        status: 15641002
      },
      fetchapi: pageNotificationMaintaion,
      visibleDrawer: false,
      visibleReadDrawer:false,
      visibleNoReadDrawer:false,
      initData:{},
      initReadData:{},
      initNoReadData:{}
    };
  },
  methods: {
    topFilterInitFun() {
      return [
        { type: 'SELECT', label: '类别', fieldName: 'notificationType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1561') },
        { type: 'INPUT', label: '主题', fieldName: 'notificationTitle', placeholder: '请输入', initialValue: '' },
        { type: 'RANGE_DATE', label: '发布时间', fieldName: 'publisDate', valueFormat: 'yyyy-MM-dd', placeholder: '请选择' },
        { type: 'SELECT', label: '紧急程度', fieldName: 'urgency', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1562') }
      ];
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row, 'show')}>
                  详情
                </el-button>
              </div>
            );
          }
        },
        {
          title: '类别',
          dataIndex: 'notificationType',
          sorter: true,
          filterItems: this.createDictList('1561'),
          render: props => {
            return <span>{this.createDictText(props.row.notificationType, '1561')}</span>;
          }
        },
        { title: '主题', dataIndex: 'notificationTitle', sorter: true },
        { title: '编号', dataIndex: 'notificationNo', sorter: true },
        {
          title: '紧急程度',
          dataIndex: 'urgency',
          sorter: true,
          filterItems: this.createDictList('1562'),
          render: props => {
            return <span>{this.createDictText(props.row.urgency, '1562')}</span>;
          }
        },
        { title: '发起部门', dataIndex: 'publishOrgName', sorter: true },
        { title: '发布人', dataIndex: 'publishPersonName', sorter: true },
        { title: '有效期至', dataIndex: 'endTime', sorter: true, dateFormat: 'yyyy-MM-dd' },
        { title: '发布时间', dataIndex: 'publishDate', dateFormat: 'yyyy-MM-dd HH:mm', sorter: true },
        {
          title: '已读数量',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'right',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.openRead(props.row,'show')}>
                  {props.row.readFeedback}
                </el-button>
              </div>
            );
          }
        },
        {
          title: '未读数量',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'right',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.openNoRead(props.row,'show')}>
                  {props.row.noReadFeedback}
                </el-button>
              </div>
            );
          }
        }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
      this.fetchParams.publisStartDate = this.fetchParams.publisDate[0];
      this.fetchParams.publisEndDate = this.fetchParams.publisDate[1];
      this.fetchParams.status = 15641002; // 查看默认搜索 已发布的状态的。
    },
    //展开收起时触发
    collapseHandle() {},
    // 已读
    openRead(row,type) {
      this.initReadData = {
        type: type,
        notificationId: row.notificationId,
        id: 1001
      };
      this.visibleReadDrawer= true
      console.log('notificationId:',row.notificationId);
    },
    // 未读
    openNoRead(row,type) {
      this.initNoReadData = {
        type: type,
        notificationId: row.notificationId,
        id: 1001
      };
      this.visibleNoReadDrawer= true
    },
    editHandle(row, type) {
      console.log('row:', row);
      this.initData = {
        type: type,
        notificationId: row.notificationId,
        id: 1001
      };
      this.visibleDrawer = true;
    },
    //关闭详情 rData 是页面关闭回调回来的数据
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    infoReadClose(rData){
      this.visibleReadDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    infoNoReadClose(rData){
      this.visibleNoReadDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
  }
};
</script>

<style lang="less" scoped>
</style>
